home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk167 / julia / julia.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  3KB  |  158 lines

  1. #include "string.h"
  2. #include "stdlib.h"
  3. #include "stdio.h"
  4. #include "math.h"
  5. #include "exec/types.h"
  6. #include "exec/nodes.h"
  7. #include "exec/lists.h"
  8. #include "exec/memory.h"
  9. #include "intuition/intuition.h"
  10. #include "iff/ifflib.h"
  11. #include "proto/all.h"
  12.  
  13. #define CMAX 40
  14.  
  15. extern struct Screen *OpenScreen();
  16.  
  17. struct GfxBase *GfxBase = NULL;
  18. struct IntuitionBase *IntuitionBase = NULL;
  19. struct Library *IFFBase = NULL;
  20.  
  21. struct RastPort *rp;
  22. struct ViewPort *vp;
  23. struct Screen *screen;
  24. struct NewScreen ns = {
  25.     0,0,    /* screen XY origin relative to View */
  26.     320,200,    /* screen width and height */
  27.     5,    /* screen depth (number of bitplanes) */
  28.     0,1,    /* detail and block pens */
  29.     NULL,    /* display modes for this screen */
  30.     CUSTOMSCREEN,    /* screen type */
  31.     NULL,    /* pointer to default screen font */
  32.     "Julia",    /* screen title */
  33.     NULL,    /* first in list of custom screen gadgets */
  34.     NULL    /* pointer to custom BitMap structure */
  35. };
  36.  
  37.  
  38. UWORD Palette[] = 
  39.   {
  40.   0x0, 0xFFF, 0xD81, 0xC70, 0xB61, 0xA52, 0x943, 0x834,
  41.   0x725, 0x616, 0x507, 0x418, 0x329, 0x23A, 0x14B, 0x5C,
  42.   0x16D, 0x27E, 0x38F, 0x49E, 0x5AD, 0x6BC, 0x7CB, 0x8DA,
  43.   0x9E9, 0xAF8, 0xBE7, 0xCD6, 0xDC5, 0xEB4, 0xFA3, 0xE92,
  44.   };
  45.   
  46. void initview()
  47. {
  48. if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0)))
  49.    {
  50.    printf("Can't open graphics library \n");
  51.    exit(0);
  52.    }
  53. if (!(IntuitionBase = (struct IntuitionBase *)
  54.                       OpenLibrary("intuition.library",0)))
  55.    {
  56.    printf("Can't open Intuition library \n");
  57.    exit(0);
  58.    }
  59. if (!(IFFBase = (struct Library *) OpenLibrary("iff.library",0)))
  60.    {
  61.    (void) printf("Copy the iff.library to your LIBS: directory!\n");
  62.    exit(10);
  63.    }
  64.  
  65. screen = OpenScreen(&ns);
  66. if (screen == NULL)
  67.    {
  68.    printf("Can't open screen \n");
  69.    exit(0);
  70.    }
  71. rp = &screen->RastPort;
  72. vp = &screen->ViewPort;
  73.  
  74. LoadRGB4(vp,Palette,(short)32);
  75.  
  76. SetDrMd(rp,JAM1);
  77. }
  78.  
  79. int inset(x,y,l)
  80. double x,y,l;
  81. {
  82. double e,x1,y1,size;
  83. int c;
  84.  
  85. c = 0; size = 0;
  86. do
  87.   {
  88.   e = exp(y);
  89.   x1 = l*cos(x)*(e+1/e)/2;
  90.   y1 = -l*sin(x)*(e-1/e)/2;
  91.   x = x1; y = y1;
  92.   size = x*x + y*y;
  93.   c++;
  94.   }
  95.   while ((c<CMAX) && (size<50));
  96. return(c);
  97. }
  98.  
  99.  
  100. /***** main program *****/
  101.  
  102. void main()
  103. {
  104. int i,j,p,fn,num;
  105. double xmax,xmin,ymin,cr,ci,cro,dx,dy,l,dl;
  106. char  filename[80];
  107. UBYTE flags = 1;
  108.  
  109. /** start **/
  110. xmax = 1.2;
  111. xmin = -1.2;
  112. printf("Exploding julia set generator - by Mike Danielsen 10/23/90\n");
  113. printf(" Starting lambda - "); scanf("%lf",&l);
  114. printf(" Lambda decrement - "); scanf("%lf",&dl);
  115. printf(" Number of plots - "); scanf("%d",&num);
  116. dx = (xmax - xmin) / 321.;
  117. dy = dx * 8.0/7.0;
  118. ymin = -100 * dy; 
  119.  
  120. initview();
  121. for (fn=0;fn<num;fn++)
  122. {
  123. cr = xmin;
  124. ci = ymin;
  125. cro = cr;
  126. for (i=0;i<100;i++)
  127.    {
  128.    for (j=0;j<160;j++)
  129.       {
  130.       p = inset(cr,ci,l);
  131.       if (p == CMAX) p = 0; 
  132.         else p = (p % 30) + 2;
  133.       SetAPen(rp,p);
  134.       WritePixel(rp,j,i);
  135.       WritePixel(rp,319-j,i);
  136.       WritePixel(rp,j,199-i);
  137.       WritePixel(rp,319-j,199-i);
  138.       cr += dx;
  139.       }
  140.    cr = cro;
  141.    ci += dy;
  142.    }
  143. sprintf(filename,"lcos.plot.%6.4f",l);
  144. if(!(SaveBitMap(filename,rp->BitMap,(WORD *)Palette,flags)))
  145.   {
  146.   printf(" save failed\n");
  147.   exit(0);
  148.   }
  149. l -= dl;  
  150. }
  151.   
  152. if(screen) CloseScreen(screen);
  153. if(IntuitionBase) CloseLibrary(IntuitionBase);
  154. if(GfxBase) CloseLibrary(GfxBase);
  155. if(IFFBase) CloseLibrary(IFFBase);
  156.  
  157. exit(TRUE);
  158. }